home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Events / EventQueue.cp < prev    next >
Text File  |  1997-06-28  |  2KB  |  98 lines

  1. // EventQueue.cp
  2.  
  3. #ifndef EventQueue_h
  4. #include "EventQueue.h"
  5. #endif
  6.  
  7. EventQueue& EventQueue::The()
  8.   {
  9.     static EventQueue the;
  10.     return the;
  11.   }
  12.  
  13. EventQueue::EventQueue()
  14.   : previous( 0 ),
  15.      current( 0 ),
  16.      next( 0 )
  17.   {
  18.   }
  19.  
  20. void EventQueue::Advance()
  21.   {
  22.     if ( previous != 0 )
  23.         events.Delete( previous );
  24.     
  25.     previous = current;
  26.     current = next;
  27.     next = 0;
  28.     
  29.     if ( current != 0 && !Valid( *current ) )
  30.       {
  31.         events.Delete( current );
  32.         current = 0;
  33.       }
  34.   }
  35.  
  36. void EventQueue::operator++()
  37.   {
  38.     Advance();
  39.  
  40.     if ( current == 0 )
  41.       {
  42.         current = new(events) EventRecord;
  43.         Assert( current != 0 );
  44.         WaitNextEvent( everyEvent, current, 0, 0 );
  45.       }
  46.   }
  47.  
  48. void EventQueue::AdvanceWithoutWaiting()
  49.   {
  50.     Advance();
  51.  
  52.     if ( current == 0 )
  53.       {
  54.         current = new(events) EventRecord;
  55.         Assert( current != 0 );
  56.         WaitNextEvent( everyEvent, current, 0, 0 );
  57.       }
  58.   }
  59.  
  60. void EventQueue::operator--()
  61.   {
  62.     Assert( previous != 0 );
  63.     Assert( current != 0 );
  64.     Assert( next == 0 );
  65.     next = current;
  66.     current = previous;
  67.     previous = 0;
  68.   }
  69.  
  70. bool EventQueue::Valid( const EventRecord& event )
  71.   {
  72.     switch( event.what )
  73.       {
  74.         case nullEvent:
  75.             return false;
  76.         
  77.         case activateEvt:
  78.         case updateEvt:
  79.             return Exists( reinterpret_cast<WindowPeek>( event.message ) );
  80.       }
  81.     
  82.     return true;
  83.   }
  84.  
  85. bool EventQueue::Exists( WindowPeek target )
  86.   {
  87.     Assert( target != 0 );
  88.     
  89.     for ( WindowPeek window = reinterpret_cast<WindowPeek>( FrontWindow() );
  90.             window != 0;
  91.             window = window->nextWindow )
  92.         if ( window == target )
  93.             return true;
  94.     
  95.     return false;
  96.   }
  97.  
  98.